<div class="layui-fluid" id="VIEW-user-pwd" lay-title="修改密码">
    <div class="layui-row layui-col-space10" action="" lay-filter="component-form-element">
        <div class="layui-card">
            <div class="layui-card-header">修改密码</div>
            <div class="layui-card-body">
                <form class="layui-form" action="">
                    <div class="layui-row layui-form-item password-block">
                        <div class="layui-col-lg4">
                            <label class="layui-form-label">原密码：</label>
                            <div class="layui-input-block">
                                <input type="password" name="ymm" lay-verify="required" placeholder="请输入原密码"
                                       autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                    </div>
                    <hr>
                    <div class="layui-form-item password-block">
                        <div class="layui-col-lg4">
                            <label class="layui-form-label">新密码：</label>
                            <div class="layui-input-block">
                                <input type="password" name="xmm" lay-verify="required" placeholder="请输入新密码"
                                       autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item password-block">
                        <div class="layui-col-lg4">
                            <label class="layui-form-label">重复密码：</label>
                            <div class="layui-input-block">
                                <input type="password" name="cmm" lay-verify="required" placeholder="请重复新密码"
                                       autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="usr-pwd-submit">
                                <i style="display: none"
                                   class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i>
                                确认修改
                            </button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['admin', 'form', 'jquery'], function (admin, form, $) {
        var view = $('#VIEW-user-pwd');

        form.render();

        view.find('[name=ymm]').focus();

        form.verify({
            password: function (value, el) {
                if (value.length < 6) return '登录密码不能少于 6 位';
            }
        });

        //提交修改密码
        form.on('submit(usr-pwd-submit)', function (data) {
            var loading = $(this).find('.layui-icon');
            if (loading.is(":visible")) return;

            admin.get({
                api: 'userPwd',
                type: 'post',
                data: data.field,
                success: function (res) {
                    if (res.code == 200) {
                        layer.alert('密码修改成功,请重新登陆', {
                            skin: 'layui-layer-lan' //样式类名
                            , closeBtn: 0
                            , anim: 4 //动画类型
                        }, function () {
                            admin.logout()
                        });
                    }
                    //view.find('[lay-filter=login-submit]').find('i').css('display', 'none');
                    //loading.css('display', 'none');
                    //view.find('[name=ymm]').focus();
                    //layer.msg(res.msg);
                },
                complete: function () {
                    //loading.hide();
                    //console.log('over');
                }
            });

            return false;
        });

    })
</script>